
import { axios } from '@/utils/request'

const api = {
    smsTypeDownList: '/admin/sms-template-type/getDownList',
    smsTypeTreeDownList: '/admin/sms-template-type/getTreeDownList',
    smsObjectList: '/admin/sms-template/getSMSTemplatePlaceholderVo',
    smsTemplateList: '/admin/sms-template/getList',
    messageSend: '/admin/messageRecord/add',

    messageRecordList: '/admin/messageRecord/list',
    messageRecipientList: '/admin/messageRecipient/appList',
    messageRecordFindBalance: '/admin/messageRecord/findBalance',
    typeMessageTemplate: '/admin/sms-template/getTypeMessageTemplate',

    wechatTemplateListByTypeId: '/admin/wechat-template/listByTypeId',
    smsTemplateTypeById: '/admin/sms-template-type/getById/',

    smsSign: '/admin/sms-template/getSmsSign' //短信签名

}

export default api



export function SmsTypeDownList() {
    return axios({
        url: api.smsTypeDownList,
        method: 'get',
    })
}

/**
  * 消息类型树下拉列表
  */
export function SmsTypeTreeDownList(params) {
    return axios({
        url: api.smsTypeTreeDownList,
        method: 'get',
        params
    })
}

/**
  * 消息关联对象下拉列表
  */
export function SmsObjectList(type) {
    return axios({
        url: api.smsObjectList + `?type=${type}`,
        method: 'get',
    })
}

/**
  * 短信消息模板
  */
export function SmsTemplateList(params) {
    return axios({
        url: api.smsTemplateList,
        method: 'get',
        params
    })
}

/**
  * 发送消息
  */
export function MessageSend(data) {
    return axios({
        url: api.messageSend,
        method: 'post',
        data,
        timeout: 0,
    })
}

/**
  * 消息列表
  */
export function MessageRecordList(params) {
    return axios({
        url: api.messageRecordList,
        method: 'get',
        params
    })
}

/**
  * 消息明细
  */
export function MessageRecipientList(params) {
    return axios({
        url: api.messageRecipientList,
        method: 'get',
        params,
        timeout: 1000 * 60
    })
}

/**
  * 获取短信剩余条数
  */
export function MessageRecordFindBalance() {
    return axios({
        url: api.messageRecordFindBalance,
        method: 'get',
    })
}

/**
  * 根据类型获取模板内容
  */
export function TypeMessageTemplate(data) {
    return axios({
        url: api.typeMessageTemplate,
        method: 'post',
        data
    })
}

/**
  * 根据类型查询微信模板列表
  */
export function WechatTemplateListByTypeId(params) {
    return axios({
        url: api.wechatTemplateListByTypeId,
        method: 'get',
        params
    })
}

/**
  * 根据类型id获取类型详情
  */
export function SmsTemplateTypeById(id) {
    return axios({
        url: api.smsTemplateTypeById + id,
        method: 'get',
    })
}

/**
  * 获取短信签名
  */
export function SmsSign() {
    return axios({
        url: api.smsSign,
        method: 'get',
    })
}


/**
  * 消息配置列表
  */
export function messagesConfigList() {
    return axios({
        url: '/admin/org-passivity-messages-config/getMapList',
        method: 'get',
    })
}

/**
 * 设置模板的状态
 * @param {*} key 
 * @param {*} enable 
 * @returns 
 */
export function setTemplateKeyEnable(key, enable) {
    return axios({
        url: `/admin/org-passivity-messages-config/setTemplateKeyEnable/${key}/${enable}`,
        method: 'post',
    })
}